package com.lanou.musicproject.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.lanou.musicproject.R;
import com.lanou.musicproject.base.BaseActivity;
import com.lanou.musicproject.bean.AlbumContent;
import com.lanou.musicproject.utils.MyConfig;
import com.lanou.musicproject.volley.VolleySingleton;
import com.squareup.picasso.Picasso;

import org.json.JSONObject;

/**
 * Created by dllo on 15/10/28.
 * 专辑页面_具体信息
 * 李东
 */
public class AlbumContentACtivity extends BaseActivity implements AdapterView.OnItemClickListener {
    private ImageView albumcontent_image;
    private VolleySingleton volleySingleton;
    private AlbumContent.DataEntity entity;
    private String album, image;
    private TextView albumcontent_name, albumcontent_publish_data, albumcontent_eypename, albumcontent_lang, albumcontent_company,
            albumcontent_description;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.albumcontent_item);
        albumcontent_image = (ImageView) findViewById(R.id.albumcontent_image);
        Intent intent = getIntent();
        if (intent != null) {
            image = intent.getStringExtra("url");
            album = MyConfig.getSharePreStr(this, "album", "albumid");
        }
        initData();
    }

    private void initData() {
        albumcontent_company = (TextView) findViewById(R.id.albumcontent_company);
        albumcontent_description = (TextView) findViewById(R.id.albumcontent_description);
        albumcontent_eypename = (TextView) findViewById(R.id.albumcontent_eypename);
        albumcontent_lang = (TextView) findViewById(R.id.albumcontent_lang);
        albumcontent_name = (TextView) findViewById(R.id.albumcontent_name);
        albumcontent_publish_data = (TextView) findViewById(R.id.albumcontent_publish_data);
        volleySingleton = VolleySingleton.getInstance(this);
        String url = "http://api.dongting.com/song/album/" +
                album +
                "?f=3030&os=4.2.2" +
                "&alf=702006&imei=865829023294149&from=android&resolution=480x854&net=2&" +
                "api_version=1.0&agent=none&v=v8.2.0.2015091720&utdid=VXAnyUVjpbcDAM8Esy5HwfD7&address" +
                "=%E8%BE%BD%E5%AE%81%E7%9C%81%E5%A4%A7%E8%BF%9E%E5%B8%82%E6%B2%99%E6%B2%B3%E5%8F%A3%E5%8C%BA%E4%BA%94%E4%B8%80%E8%B7%AF314&userId=0" +
                "&longitude=121.54476&user_id=0&latitude=38.88355&language=zh";
        Picasso.with(this).load(image).into(albumcontent_image);
        JsonObjectRequest jr = new JsonObjectRequest(url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                String str = response.toString();
                AlbumContent content = JSON.parseObject(str, AlbumContent.class);
                entity = content.getData();

                albumcontent_publish_data.setText(entity.getPublishDate());
                albumcontent_name.setText(entity.getName());
                albumcontent_eypename.setText(entity.getTypeName());
                albumcontent_lang.setText(entity.getLang());
                albumcontent_company.setText(entity.getCompanyName());
                albumcontent_description.setText(entity.getDescription());

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        volleySingleton.addQueue(jr);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }
}
